﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace TahsilatGirisi
{
    public class ComboItem
    {
        public object Value { get; set; }
        public string Text { get; set; }
        public override string ToString()
        {
            return Text;
        }
    }



    public class ExCombo : DevExpress.XtraEditors.ComboBoxEdit
    {
        private DataTable dt;
        public DataTable DataSource
        {
            get
            {
                return dt;
            }
            set
            {
                dt = value;
                if (dt != null)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        ComboItem item = new ComboItem();
                        item.Text = dt.Rows[i][DisplayMember].ToString();
                        item.Value = dt.Rows[i][ValueMember];
                        this.Properties.Items.Add(item);
                    }
                }
            }
        }

        public string DisplayMember { get; set; }
        public string ValueMember { get; set; }

        public object SelectedValue
        {
            get
            {
                if (this.SelectedIndex > -1)
                {
                    return ((ComboItem)this.SelectedItem).Value;
                }
                else
                {
                    return null;
                }
            }
        }

    }
}
